package final2107.day01;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class StudentTest {
    public static void main(String[] args) {

        List<Student> list = new ArrayList<>();
        Student student1 = new Student(1002,"tom",23);
        Student student2 = new Student(1001,"tony",21);
        Student student3 = new Student(1005,"jack",22);
        Student student4 = new Student(1008,"rose",28);
        Student student5 = new Student(1003,"jerry",25);

        list.add(student1);
        list.add(student2);
        list.add(student3);
        list.add(student4);
        list.add(student5);

//        Collections.sort(list);
        Collections.sort(list, new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                return o2.getAge().compareTo(o1.getAge());
            }
        });

        for (Student s:list) {
            System.out.println(s);
        }
    }
}
